pyltp安装(pyltp4.0.0)内附各种版本语法bug解决方式(绝对详细)【包含语法改动说明】 | 您所在的位置:网站首页 › error c2238如何解决 › pyltp安装(pyltp4.0.0)内附各种版本语法bug解决方式(绝对详细)【包含语法改动说明】 |
可以先参考这位博主的保姆级教程,写得非常好。 pyltp安装教程——保姆级_pyltp wheel 文件-CSDN博客 但是pyltp以及python版本不对版的问题使安装pyltp仍然报了很多bug。 基于上一篇的教程,如果遇到 ERROR: pyltp-0.2.1-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform. 可以先参考 【2023新教程】解决is not a supported wheel on this platform-解决pip has no attribute pep425tags-解决网上旧教程不适用的问题_is not a supported wheel on this platform.-CSDN博客 这篇教程主要的意思是:找到最相近的名字,改写whl。 我尝试后,得到的结果是成功安装了,甚至进入anaconda的环境目录搜都能搜到pyltp,但就是import报错,会划红线。 我的解决方法是: 删除在lib的包下所有的pyltp文件,然后直接在python里 pip install pyltp 成功后,不需要把ltp的v3.4.0换掉,继续用它。 创建一个py文件尝试样例: import os from pyltp import Segmentor LTP_DIR='D:\Program Files\myLTP\ltp_data_v3.4.0' # ltp模型目录的路径 cws_model_path=os.path.join(LTP_DIR,'cws.model') # 分词模型路径,模型名称为`cws.model` segmentor=Segmentor() # 初始化实例 segmentor.load(cws_model_path) # 加载模型 words=segmentor.segment('熊高雄你吃饭了吗') # 分词 print('\t'.join(words)) segmentor.release() # 释放模型会出现报错: 1. pyltp.Segmentor(model_path: str, lexicon_path: str = None, force_lexicon_path: str = None) 这是因为segmentor的语句变了 对于这两行: segmentor=Segmentor() # 初始化实例 segmentor.load(cws_model_path) # 加载模型要改成: segmentor=Segmentor(cws_model_path)另外,调用Postagger和parser也是一样(但这两个错了是不会报错的,但会运行不出,所以请一定注意) segmentor = Segmentor(cws_model_path) postagger = Postagger(pos_model_path) parser = Parser(par_model_path)另外,可能还有朋友会遇到: 'tuple' object has no attribute 'head' 的报错 请把 (arc.head, arc.relation) for arc in arcs) 改成 (arc[0], arc[1]) for arc in arcs) 以及: 在使用lexcion时,segmentor.load_with_lexicon也一同被弃用了。需要在定义的时候直接加入file path segmentor = Segmentor(cws_model_path, 'lexicon.txt')注意:必须是英文名,否则会报错找不到相应的文件。 |
CopyRight 2018-2019 实验室设备网 版权所有 |